from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand

from exts import db
from sayhello import create_app


app = create_app()

# 使用flask-script扩展对app进行绑定
manager = Manager(app=app)  # flask-script命令

# 数据库命令的配置
migrate = Migrate(app=app, db=db)
# 把命令添加到flask-script命令,MigrateCommand这个只有flask_migrate版本是2.5.3才具有的 此时的flask的版本必须是1.1.2
manager.add_command('db', MigrateCommand)

# @app.route('/', methods=['GET', 'POST'])
# def index():
#     # 创建一个表单对象
#     form = HelloForm()
#     # 验证表单
#     if form.validate_on_submit():
#         # 获取表单数据
#         name = form.name.data
#         body = form.body.data
#         message = Message(body=body, name=name)
#         db.session.add(message)
#         db.session.commit()
#         flash('你的留言已经成功提交啦!')
#         return redirect(url_for('index'))
#     # 从数据库查询留言
#     messages = Message.query.order_by(Message.timestamp.desc()).all()
#     return render_template('index.html', form=form, messages=messages)


# # 设置404页面
# @app.errorhandler(404)
# def page_not_found(e):
#     return render_template('errors/404.html')
#
#
# # 设置500页面
# @app.errorhandler(500)
# def internal_server_error(e):
#     return render_template('errors/500.html')


if __name__ == '__main__':
    manager.run()
